#include "PauseScene.h"



PauseScene::PauseScene()
{
	_startTime=0;
	_cursorIndex=0;
	_mute=false;
}

PauseScene::~PauseScene()
{
}




void PauseScene::Update(float DeltaTime)
{
	
	_ProcessInput();
	
	
}

void PauseScene::Render()
{
	ResourceManager *_ResourceManager=ResourceManager::GetInstance();

	_d3ddv->Clear( 0, NULL, D3DCLEAR_TARGET,D3DCOLOR_XRGB( 0,255,255 ), 1.0f, 0 );

	_ResourceManager->GetSurface(_ResourceManager->SurfaceName.PauseScene_Background)->Draw(_backBuffer,NULL,NULL);

	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.PauseScene_Resume)->Get_Texture(),0,0,&D3DXVECTOR3(400-122/2,175,0),D3DCOLOR_XRGB(253, 253, 253));
	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.PauseScene_Menu)->Get_Texture(),0,0,&D3DXVECTOR3(400-122/2,220,0),D3DCOLOR_XRGB(253, 253, 253));
	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.PauseScene_Mute)->Get_Texture(),0,0,&D3DXVECTOR3(400-122/2,265,0),D3DCOLOR_XRGB(253, 253, 253));
	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.PauseScene_Quit)->Get_Texture(),0,0,&D3DXVECTOR3(400-122/2,310,0),D3DCOLOR_XRGB(253, 253, 253));
	_spriteHandler->Draw(_ResourceManager->GetTexture(_ResourceManager->TextureName.PauseScene_Highlight)->Get_Texture(),0,0,&D3DXVECTOR3(400-135/2,200+45*_cursorIndex,0),D3DCOLOR_XRGB(253, 253, 253));
}

void PauseScene::Leave()
{
	// Giai phong bo nho

	
}

void PauseScene::Pause()
{
	// Tam thoi ngung hoat dong
}

void PauseScene::Resume()
{
	// Tai hoat dong
}

void PauseScene::_ProcessInput()
{

	if (CGame::GetInstance()->GetInput()->IsKeyDown(DIK_DOWN))
	{
		float delta=GetTickCount()-_startTime;
		if(delta>200)
		{
				switch(_cursorIndex)
				{
					case 0:  _cursorIndex=1; break;
					case 1:  _cursorIndex=2; break;
					case 2:  _cursorIndex=3; break;
					case 3:  _cursorIndex=0; break;
				}
		
				ResourceManager::GetInstance()->GetSound(ResourceManager::GetInstance()->SoundName.MenuChange)->Play(false);
				_startTime=GetTickCount();
		
		}
	}
	else if(CGame::GetInstance()->GetInput()->IsKeyDown(DIK_UP))
	{
		
		float delta=GetTickCount()-_startTime;
		if(delta>200)
		{
				switch(_cursorIndex)
				{
					case 0:  _cursorIndex=3; break;
					case 1:  _cursorIndex=0; break;
					case 2:  _cursorIndex=1; break;
					case 3:  _cursorIndex=2; break;
				}
		
				ResourceManager::GetInstance()->GetSound(ResourceManager::GetInstance()->SoundName.MenuChange)->Play(false);
				_startTime=GetTickCount();		
		}
	}
	else if(CGame::GetInstance()->GetInput()->IsKeyDown(DIK_RETURN))
	{
		ResourceManager::GetInstance()->GetSound(ResourceManager::GetInstance()->SoundName.MenuChange)->Play(false);

		float delta=GetTickCount()-_startTime;

		if(delta>200)
		{
			switch(_cursorIndex)
			{
				case 0: SceneManager::GetInstance()->PopScene(); break;
				case 1:
					{
						SceneManager::GetInstance()->GoToFirst();
						MenuScene* newMenu=(MenuScene*)SceneManager::GetInstance()->GetCurrentScene();
						newMenu->SetLock(true);
						break;
					}
				case 2:
					{
						if(_mute)
						{
							_mute=false;
							ResourceManager::GetInstance()->MuteAll(_mute);
							// Doi chuoi ki tu
						}
						else 
						{
							_mute=true;
							ResourceManager::GetInstance()->MuteAll(_mute);
							// Doi chuoi ki tu
						}
						break;
					}
				case 3: PostMessage(_hWnd,WM_QUIT,0,0); break;
			}
		}
		_startTime=GetTickCount();
		
	}


}

